<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Iterator Based Parser API</title>
<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../../index.html" title="Spirit 2.59">
<link rel="up" href="../parse_api.html" title="Parser API">
<link rel="prev" href="../parse_api.html" title="Parser API">
<link rel="next" href="stream_api.html" title="Stream Based Parser API">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../parse_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../parse_api.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="stream_api.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="spirit.qi.reference.parse_api.iterator_api"></a><a class="link" href="iterator_api.html" title="Iterator Based Parser API">Iterator
          Based Parser API</a>
</h5></div></div></div>
<h6>
<a name="spirit.qi.reference.parse_api.iterator_api.h0"></a>
            <span class="phrase"><a name="spirit.qi.reference.parse_api.iterator_api.description"></a></span><a class="link" href="iterator_api.html#spirit.qi.reference.parse_api.iterator_api.description">Description</a>
          </h6>
<p>
            The library provides a couple of free functions to make parsing a snap.
            These parser functions have two forms. The first form <code class="computeroutput"><span class="identifier">parse</span></code>
            works on the character level. The second <code class="computeroutput"><span class="identifier">phrase_parse</span></code>
            works on the phrase level and requires skip parser. Both versions can
            take in attributes by reference that will hold the parsed values on a
            successful parse.
          </p>
<h6>
<a name="spirit.qi.reference.parse_api.iterator_api.h1"></a>
            <span class="phrase"><a name="spirit.qi.reference.parse_api.iterator_api.header"></a></span><a class="link" href="iterator_api.html#spirit.qi.reference.parse_api.iterator_api.header">Header</a>
          </h6>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/parse.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_parse</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            For variadic attributes:
          </p>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/parse_attr.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_parse_attr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            The variadic attributes version of the API allows one or more attributes
            to be passed into the parse functions. The functions taking two or more
            are usable when the parser expression is a <a class="link" href="../operator/sequence.html" title="Sequence Parser (a &gt;&gt; b)">Sequence</a>
            only. In this case each of the attributes passed have to match the corresponding
            part of the sequence.
          </p>
<p>
            For the API functions deducing the correct (matching) parser type from
            the supplied attribute type:
          </p>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/detail/parse_auto.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_parse_auto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
          </p>
<h6>
<a name="spirit.qi.reference.parse_api.iterator_api.h2"></a>
            <span class="phrase"><a name="spirit.qi.reference.parse_api.iterator_api.namespace"></a></span><a class="link" href="iterator_api.html#spirit.qi.reference.parse_api.iterator_api.namespace">Namespace</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                    <p>
                      Name
                    </p>
                  </th></tr></thead>
<tbody>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">parse</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">phrase_parse</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">skip_flag</span><span class="special">::</span><span class="identifier">postskip</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">skip_flag</span><span class="special">::</span><span class="identifier">dont_postskip</span></code>
                    </p>
                  </td></tr>
</tbody>
</table></div>
<h6>
<a name="spirit.qi.reference.parse_api.iterator_api.h3"></a>
            <span class="phrase"><a name="spirit.qi.reference.parse_api.iterator_api.synopsis"></a></span><a class="link" href="iterator_api.html#spirit.qi.reference.parse_api.iterator_api.synopsis">Synopsis</a>
          </h6>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">qi</span>
<span class="special">{</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">parse</span><span class="special">(</span>
        <span class="identifier">Iterator</span><span class="special">&amp;</span> <span class="identifier">first</span>
      <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">parse</span><span class="special">(</span>
        <span class="identifier">Iterator</span><span class="special">&amp;</span> <span class="identifier">first</span>
      <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Attr1</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Skipper</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">phrase_parse</span><span class="special">(</span>
        <span class="identifier">Iterator</span><span class="special">&amp;</span> <span class="identifier">first</span>
      <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">skipper</span>
      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">skip_flag</span><span class="special">)</span> <span class="identifier">post_skip</span> <span class="special">=</span> <span class="identifier">skip_flag</span><span class="special">::</span><span class="identifier">postskip</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Skipper</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">phrase_parse</span><span class="special">(</span>
        <span class="identifier">Iterator</span><span class="special">&amp;</span> <span class="identifier">first</span>
      <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">skipper</span>
      <span class="special">,</span> <span class="identifier">Attr1</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Skipper</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">phrase_parse</span><span class="special">(</span>
        <span class="identifier">Iterator</span><span class="special">&amp;</span> <span class="identifier">first</span>
      <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span>
      <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">skipper</span>
      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">skip_flag</span><span class="special">)</span> <span class="identifier">post_skip</span>
      <span class="special">,</span> <span class="identifier">Attr1</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>
<span class="special">}}}</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              Starting with <a href="http://boost-spirit.com" target="_top">Spirit</a> V2.5
              (distributed with Boost V1.47) the placeholder <code class="computeroutput"><span class="identifier">_val</span></code>
              can be used in semantic actions attached to top level parser components.
              In this case <code class="computeroutput"><span class="identifier">_val</span></code> refers
              to the supplied attribute as a whole. For API functions taking more
              than one attribute argument <code class="computeroutput"><span class="identifier">_val</span></code>
              will refer to a Fusion vector or references to the attributes.
            </p></td></tr>
</table></div>
<p>
            <span class="emphasis"><em>Spirit.Qi</em></span> parser API functions based on the automatic
            creation of the matching parser type:
          </p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">qi</span>
<span class="special">{</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">parse</span><span class="special">(</span>
        <span class="identifier">Iterator</span><span class="special">&amp;</span> <span class="identifier">first</span>
      <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span>
      <span class="special">,</span> <span class="identifier">Attr</span><span class="special">&amp;</span> <span class="identifier">attr</span><span class="special">);</span>


    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Skipper</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="keyword">bool</span>
    <span class="identifier">phrase_parse</span><span class="special">(</span>
        <span class="identifier">Iterator</span><span class="special">&amp;</span> <span class="identifier">first</span>
      <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span>
      <span class="special">,</span> <span class="identifier">Attr</span><span class="special">&amp;</span> <span class="identifier">attr</span>
      <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">skipper</span>
      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">skip_flag</span><span class="special">)</span> <span class="identifier">post_skip</span> <span class="special">=</span> <span class="identifier">skip_flag</span><span class="special">::</span><span class="identifier">postskip</span><span class="special">);</span>
<span class="special">}}}</span>
</pre>
<p>
            All functions above return <code class="computeroutput"><span class="keyword">true</span></code>
            if none of the involved parser components failed, and <code class="computeroutput"><span class="keyword">false</span></code>
            otherwise.
          </p>
<p>
            The maximum number of supported arguments is limited by the preprocessor
            constant <code class="computeroutput"><span class="identifier">SPIRIT_ARGUMENTS_LIMIT</span></code>.
            This constant defaults to the value defined by the preprocessor constant
            <code class="computeroutput"><span class="identifier">PHOENIX_LIMIT</span></code> (which
            in turn defaults to <code class="computeroutput"><span class="number">10</span></code>).
          </p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              The variadic functions with two or more attributes internally combine
              references to all passed attributes into a <code class="computeroutput"><span class="identifier">fusion</span><span class="special">::</span><span class="identifier">vector</span></code>
              and forward this as a combined attribute to the corresponding one attribute
              function.
            </p></td></tr>
</table></div>
<p>
            The <code class="computeroutput"><span class="identifier">phrase_parse</span></code> functions
            not taking an explicit <code class="computeroutput"><span class="identifier">skip_flag</span></code>
            as one of their arguments invoke the passed skipper after a successful
            match of the parser expression. This can be inhibited by using the other
            versions of that function while passing <code class="computeroutput"><span class="identifier">skip_flag</span><span class="special">::</span><span class="identifier">dont_postskip</span></code>
            to the corresponding argument.
          </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Parameter
                    </p>
                  </th>
<th>
                    <p>
                      Description
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Iterator</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      <a href="http://en.cppreference.com/w/cpp/named_req/ForwardIterator" target="_top"><code class="computeroutput"><span class="identifier">ForwardIterator</span></code></a> pointing
                      to the source to parse.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Expr</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      An expression that can be converted to a Qi parser.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Skipper</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      Parser used to skip white spaces.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Attr</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      An attribute type utilized to create the corresponding parser
                      type from.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Attr1</span></code>, <code class="computeroutput"><span class="identifier">Attr2</span></code>, ..., <code class="computeroutput"><span class="identifier">AttrN</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      One or more attributes.
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../parse_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../parse_api.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="stream_api.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
